/**
 * 
 */
package com.huniu.links.hive;

import java.io.File;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import com.huniu.links.colony.IScoutBeeBehavior;
import com.huniu.links.colony.ScoutBeeBehaviorImpl;
import com.huniu.utility.DateUtil;

/**
 * @author zandy (chenheng)
 *
 */
public class ScoutBeeBehaviorPoolImpl implements IScoutBeeBehaviorPool {
	
	private List<File> seedFileList ;
	private String linkFolder;
	
	public void setLinkFolder(String linkFolder) {
		this.linkFolder = linkFolder;
	}

	public void setSeedFileList(List<File> seedFileList) {
		this.seedFileList = seedFileList ;
	}
	
	public void execute() {
		String linkFolder = generateLinkFolder();
		ExecutorService executor = Executors.newCachedThreadPool();
		for ( File file : seedFileList ) {
			IScoutBeeBehavior scoutBehavior = new ScoutBeeBehaviorImpl();
			scoutBehavior.setSeedFile(file);
			scoutBehavior.setLinkFolder(linkFolder);
			executor.execute(scoutBehavior);
		}
		executor.shutdown();
	}
	
	private String generateLinkFolder() {
		GregorianCalendar calender = new GregorianCalendar();
		Date currentDate = calender.getTime();
		String childFolder = DateUtil.convertDateToString(currentDate,
				DateUtil.DATE_FORMAT_1);
		String folder = linkFolder + File.separator + childFolder;
		File file = new File(folder);
		if (! file.exists()) {
			file.mkdirs();
		}
		return folder ;
	}
}
